<?php

namespace app\webapi\controller;

use app\webapi\common\BaseController;
use app\webapi\vms\service\TemplateService;
use app\webapi\vms\validate\TemplateValidate;
use think\App;

/**
 * @模板控制器
 */
class TemplateController extends BaseController
{
    /**
     * @var TemplateValidate
     */
    protected $validate;

    /**
     * @var TemplateService
     */
    protected $service;

    protected $website_id = 1;

    /**
     * @param App $app
     */
    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->validate = new TemplateValidate();
        $this->service = new TemplateService();
    }

    /**
     * @desc 获取模板分类列表
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author zhaozhiwei
     * @time 2023/12/12-13:50
     */
    public function getCategoryList()
    {
        $res = $this->service->getCategoryList();
        return $this->responseSuccess($res);
    }

    /**
     * @desc 获取模板分页列表
     * @return \think\response\Json
     * @author zhaozhiwei
     * @time 2023/12/12-13:50
     */
    public function getPaginateList()
    {
        $params = $this->validate->goCheck('getPaginateList');
        $res = $this->service->getPaginateList($params['page_no'], $params['page_size'], $params['category_id'] ?? '', $this->website_id);
        return $this->responseSuccess($res);
    }

    /**
     * @desc 立即使用模板
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author zhaozhiwei
     * @time 2023/12/19-10:20
     */
    public function immediateUse()
    {
        $params = $this->validate->goCheck('immediateUse');
        $res = $this->service->immediateUse($params['id'], $this->website_id);
        return $this->responseSuccess($res);
    }

}